package com.lq.educationsystem.teacher.service.impl;

import com.lq.educationsystem.common.constant.ResultContant;
import com.lq.educationsystem.common.util.Result;
import com.lq.educationsystem.common.util.ResultBuild;
import com.lq.educationsystem.teacher.entiy.TeacherTb;
import com.lq.educationsystem.teacher.mapper.TeacherTbMapper;
import com.lq.educationsystem.teacher.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TeacherServiceImpl implements TeacherService {
    //调用mapper
    @Autowired
    TeacherTbMapper teacherTbMapper;

    @Override
    public Result<TeacherTb> teacherLogin(TeacherTb teacherInfo) {
        /**
         * 通过教师账号查询功能
         */
        TeacherTb teacherQueryInfo = teacherTbMapper.queryTeacherInfoByTeacherAccount(teacherInfo);

        if (teacherQueryInfo == null) {
            Result<TeacherTb> teacherTbResult = new Result<>();
            //失败状态
            teacherTbResult.setCode(ResultContant.DEFEAT_RESULT.getCode());
            teacherTbResult.setMessage("用户名不存在");
            //用户名不存在
            return teacherTbResult;
        }else {
            //用户名存在

            //密码错误
            if (!teacherInfo.getTeacherPassword().equals(teacherQueryInfo.getTeacherPassword())) {
                Result<TeacherTb> teacherTbResult = new Result<>();
                //失败状态
                teacherTbResult.setCode(ResultContant.DEFEAT_RESULT.getCode());
                teacherTbResult.setMessage("用户名错误");
                //用户名不存在
                return teacherTbResult;
            }else {
                return ResultBuild.buildOk(teacherQueryInfo);
            }
        }

    }
}
